package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectDemo5 {
    public static void main(String[] args) throws NoSuchMethodException, InstantiationException, IllegalAccessException, ClassNotFoundException, InvocationTargetException {
        Person p=new Person();
        p.say("hello");
        Class cls=Class.forName("reflect.Person");
        Object obj=cls.newInstance();
        Method method=cls.getMethod("say",String.class);
        method.invoke(obj,"你好");
        Person p2=new Person("佳佳",8);
        p2.say("hello",2);
        Class cls1=Class.forName("reflect.Person");
        Object obj1=cls1.newInstance();
        Method method1=cls1.getMethod("say",String.class,int.class);
        method1.invoke(obj1,"你好",2);
    }
}
